package fr.greta.centre.dao;

import java.sql.*;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

public class Bd {
	private static DataSource ds;

	// static private Connection connect = null;

	static public Connection getConnect() throws SQLException {
		// if (connect != null){
		// return connect;
		// }else{
		//
		Connection connect = null;
		try {
			Context ctx = new InitialContext();
			ds = (DataSource) ctx.lookup("java:comp/env/jdbc/Bd");
			/*
			 * System.out.println("context namespace :" + ds.toString() + "\n");
			 * System.out.println("context factory :" +
			 * ctx.INITIAL_CONTEXT_FACTORY + "\n");
			 */
			connect = ds.getConnection();
		} catch (SQLException e) {
			System.out.println("connection bdd marche pas" + e);
			e.printStackTrace();
			throw e;

		} catch (NamingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return connect;
		// }

	}

}
